package rachitmagon.myfirstapp;

import android.app.*;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.google.zxing.integration.android.*;
public class Menu extends ListActivity{

	String classes[] = {"MainActivity","example1","example2","example3","example4",
			"example5","example6"};
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		
		super.onListItemClick(l, v, position, id);
		
//		try {
//			Class ourClass;
//			ourClass = Class.forName("rachitmagon.myfirstapp." + classes[position]);
//			Intent ourIntent = new Intent(Menu.this,ourClass);
//			startActivity(ourIntent);
//			
//		} catch (ClassNotFoundException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		IntentIntegrator integrator = new IntentIntegrator(Menu.this);
		integrator.initiateScan();
		
	}
	
	 
		  public void onActivityResult(int requestCode, int resultCode, Intent intent) {
		    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
		    if (scanResult != null) {
		      // handle scan result
		    	
		    	AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
		    	if(scanResult.getContents().equalsIgnoreCase("8901719255144"))
		    	{
		    		dlgAlert.setMessage("You found a Parle G :)");
			    	dlgAlert.setTitle("Congrats!");
		    	}
		    	else
		    	{
		    		dlgAlert.setMessage(scanResult.getContents());
			    	dlgAlert.setTitle("Sorry :(");
		    	}
		    	dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface arg0, int arg1) {
						// TODO Auto-generated method stub
						
					}
				});
		    	dlgAlert.setCancelable(true);
		    	dlgAlert.create().show();
		    	
		    }
		    // else continue with any other code you need in the method
		   
		  }
		  
		 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	
		super.onCreate(savedInstanceState);
		setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, classes));
	}
	

}
